package com.antd.admin.server.strategy.data;

import com.antd.admin.api.dto.RoleDTO;
import com.antd.common.data.enums.DataScopeTypeEnum;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author: 冷言丶冷语
 * @create: 2020-10-27 10:43
 */
@Component
public class DataScopeContext {
    @Autowired
    private final Map<String,AbstractDataScopeHandler> strategyMap= Maps.newConcurrentMap();

    public DataScopeContext(Map<String, AbstractDataScopeHandler> strategyMap){
        strategyMap.forEach(this.strategyMap::put);
    }
    public List<String> getDeptIdsForDataScope(RoleDTO roleDTO, Integer type){
        return strategyMap.get(String.valueOf(roleDTO.getDsType())).getDeptIds(roleDTO, DataScopeTypeEnum.valueOf(type));
    }
}
